package com.sgb.jicai.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.jicai.base.JiCaiBaseApi;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.jicai.entity.JcCountEntity;
import com.sgb.jicai.view.activity.MyCenterMyJoinActivity;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MToast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyCenterMyJoinModel extends ViewModel {

    private MyCenterMyJoinActivity activity;


    public void getFirstTabDatas() {
        List<PickSelectEntity> datas = new ArrayList<>();
        datas.add(new PickSelectEntity("1", "需方发起"));
        datas.add(new PickSelectEntity("2", "企业专项"));
        datas.add(new PickSelectEntity("100", "供方发起"));
        activity.updateFirstTabData(datas);
    }

    public List getSecondTabDatas() {
        List<PickSelectEntity> datas = new ArrayList<>();
        datas.add(new PickSelectEntity("0", "全部"));
        datas.add(new PickSelectEntity("1", "集采中"));
        datas.add(new PickSelectEntity("2", "集采完成"));
        return datas;
    }

    /**
     * 需方发起使用
     * 刷新数量
     */
    public void getMyGroupBuyListCount(String groupbuyMode, String searchWords) {
        Map map = new HashMap();
//        map.put("groupBuyType", groupBuyType);//1即报集采 2汇总集采 3企业专项
        map.put("groupBuyMode", groupbuyMode);//1需方发起 2企业专项
        map.put("goodsName", searchWords);
        JiCaiBaseApi.getApi().getMyParticipantCountForStatus(map).enqueue(new ICallBack<BaseEntity<List<JcCountEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<JcCountEntity>> data) {
                if (data.getData() == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(JiCaiBaseApi.RESPONSE_OK)) {
                    activity.setTabNum(data.getData());
                } else {
                    MToast.showToast(activity, data.getMsg());
                }
            }
        });
    }

    /**
     * 供方发起使用
     * 刷新数量
     */
    public void getMyOfferBuyListCount(String searchWords) {
//        Map map = new HashMap();
//        map.put("type", 2);//搜索类型：1，自己发起的集采。2，加盟的集采
//        map.put("goodsName", searchWords);
        JiCaiBaseApi.getApi().getMyProductListCountForStatus(searchWords, 2).enqueue(new ICallBack<BaseEntity<List<JcCountEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<JcCountEntity>> data) {
                if (data.getData() == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(JiCaiBaseApi.RESPONSE_OK)) {
                    activity.setTabNum(data.getData());
                } else {
                    MToast.showToast(activity, data.getMsg());
                }
            }
        });
    }


    public void setActivity(MyCenterMyJoinActivity myCenterMyJoinActivity) {
        this.activity = myCenterMyJoinActivity;
    }
}
